package top.archiesean.gateway.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.reactive.config.EnableWebFlux;
import top.archiesean.gateway.filter.PasswordDecoderFilter;
import top.archiesean.gateway.filter.RequestGlobalFilter;
import top.archiesean.gateway.handler.GlobalExceptionHandler;
import top.archiesean.gateway.properties.GatewayConfigProperties;

/**
 * @author ArchieSean
 * @description 网关配置类
 * @date 2024-02-18 21:27
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(GatewayConfigProperties.class)
public class GatewayConfiguration {

    /**
     * 登录密码解密过滤器
     *
     * @param properties 配置文件
     * @return PasswordDecoderFilter
     */
    @Bean
    public PasswordDecoderFilter passwordDecoderFilter(GatewayConfigProperties properties) {
        return new PasswordDecoderFilter(properties);
    }

    /**
     * 全局过滤器
     *
     * @return RequestGlobalFilter
     */
    @Bean
    public RequestGlobalFilter requestGlobalFilter() {
        return new RequestGlobalFilter();
    }


    /**
     * webflux 异常处理
     * @param objectMapper obj
     * @return handler
     */
    @Bean
    public GlobalExceptionHandler globalExceptionHandler(ObjectMapper objectMapper) {
        return new GlobalExceptionHandler(objectMapper);
    }
}
